package com.priox.sigar.application.mappers.handler;

import com.mm.support.domain.TipoUsuario;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@MappedTypes(TipoUsuario.class)
public class TipoUsuarioTypeHandler implements TypeHandler<TipoUsuario> {

    public void setParameter(PreparedStatement preparedStatement, int i, TipoUsuario item, JdbcType jdbcType) throws SQLException {
        preparedStatement.setLong(i, item.getCode());
    }

    public TipoUsuario getResult(ResultSet resultSet, String s) throws SQLException {
        return TipoUsuario.findByCode(new Long(resultSet.getString(s)));
    }

    public TipoUsuario getResult(CallableStatement callableStatement, int i) throws SQLException {
        return TipoUsuario.findByCode(callableStatement.getLong(i));
    }
}
